package com.xzqwjw.taskmanager.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.leaderinfo.model.InfoEducation;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class EducationDao implements com.leaderinfo.service.OperateDatabaseService {

	private SQLiteDatabase objDB;
	private String strDBFile;

	public EducationDao(String strDBFile) {
		this.strDBFile = strDBFile;
	}

	// �����Զ���ŵõ�һ����¼�ľ�����Ϣ�������浽һ��Map�����У���Map����ֻ����һ��InfoEducation
	@Override
	public Map<String, Object> getRecordByAID(int intAID) {
		InfoEducation objEdu = null;
		Map<String, Object> mapInfo = null;

		objDB = SQLiteDatabase.openOrCreateDatabase(strDBFile, null);

		String strSQL = "SELECT * FROM info_cadre_education WHERE aid=?";
		String[] aryArgs = { String.valueOf(intAID) };

		Cursor objCursor = objDB.rawQuery(strSQL, aryArgs);
		if (objCursor.moveToFirst()) {
			objEdu = new InfoEducation();
			getInfo(objCursor, objEdu);
			mapInfo = new HashMap<String, Object>();
			mapInfo.put("EducationInfo", objEdu);
		}
		objCursor.close();
		objDB.close();
		return mapInfo;
	}

	@Override
	public Map<String, Object> getRecordByBasicID(int intBasicID) {
		return null;
	}

	// ����BasicID��ѯĳ�����й���Щ��������
	@Override
	public List<Map<String, Object>> getRecordsByBasicID(int intBasicID) {
		List<Map<String, Object>> listInfo = new ArrayList<Map<String, Object>>();
		Map<String, Object> mapInfo = null;
		InfoEducation objEdu = null;

		objDB = SQLiteDatabase.openOrCreateDatabase(strDBFile, null);

		String strSQL = "SELECT * FROM info_cadre_education WHERE id_basic=? ORDER BY aid DESC";
		String[] aryArgs = { String.valueOf(intBasicID) };

		Cursor objCursor = objDB.rawQuery(strSQL, aryArgs);
		while (objCursor.moveToNext()) {
			mapInfo = new HashMap<String, Object>();
			objEdu = new InfoEducation();
			getInfo(objCursor, objEdu);
			mapInfo.put("EducationInfo", objEdu);
			listInfo.add(mapInfo);
		}
		objCursor.close();
		objDB.close();
		return listInfo;
	}
	
	@Override
	public List<Map<String, Object>> getAllRecords() {
		return null;
	}

	// ��������Ϣ�浽һ��InfoEducation��
	private void getInfo(Cursor objCursor, InfoEducation objEdu) {
		objEdu.AID = objCursor.getInt(objCursor.getColumnIndex("aid"));
		objEdu.BasicID = objCursor
				.getInt(objCursor.getColumnIndex("id_basic"));
		objEdu.EducationType = objCursor.getString(objCursor
				.getColumnIndex("education_type"));
		objEdu.Education = objCursor.getString(objCursor
				.getColumnIndex("education"));
		objEdu.EducationDegree = objCursor.getString(objCursor
				.getColumnIndex("education_degree"));
		objEdu.GraduateSchool = objCursor.getString(objCursor
				.getColumnIndex("graduate_school"));
		objEdu.Specialty = objCursor.getString(objCursor
				.getColumnIndex("specialty"));
		objEdu.DateEnter = objCursor.getString(objCursor
				.getColumnIndex("date_enter"));
		objEdu.DateEnd = objCursor.getString(objCursor
				.getColumnIndex("date_end"));
		objEdu.DegreeTime = objCursor.getString(objCursor
				.getColumnIndex("degree_time"));
		objEdu.EducationYear = objCursor.getString(objCursor
				.getColumnIndex("education_year"));
	}

	@Override
	public List<Map<String, Object>> getRecordsByWhere(String strWhere) {
		return null;
	}

	
}
